<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="议题名称" prop="agendaName">
        <el-input
          v-model="queryParams.agendaName"
          placeholder="请输入议题名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="议题编码" prop="agendaCode">
        <el-input
          v-model="queryParams.agendaCode"
          placeholder="请输入议题编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="议题任务来源" prop="agendaResource">
        <el-input
          v-model="queryParams.agendaResource"
          placeholder="请输入议题任务来源"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专项名称" prop="specialItemName">
        <el-input
          v-model="queryParams.specialItemName"
          placeholder="请输入专项名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="事项编码" prop="itemCode">
        <el-input
          v-model="queryParams.itemCode"
          placeholder="请输入事项编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="关联议题编码" prop="relatedAgendaCode">
        <el-input
          v-model="queryParams.relatedAgendaCode"
          placeholder="请输入关联议题编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参会人" prop="participant">
        <el-input
          v-model="queryParams.participant"
          placeholder="请输入参会人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="领导审议意见" prop="mettingComment">
        <el-input
          v-model="queryParams.mettingComment"
          placeholder="请输入领导审议意见"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="议题是否通过（0否，1是）" prop="passable">
        <el-input
          v-model="queryParams.passable"
          placeholder="请输入议题是否通过（0否，1是）"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="议题是否上报国资委（0否，1是）" prop="reportable">
        <el-input
          v-model="queryParams.reportable"
          placeholder="请输入议题是否上报国资委（0否，1是）"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否听取意见（0否，1是）" prop="consultable">
        <el-input
          v-model="queryParams.consultable"
          placeholder="请输入是否听取意见（0否，1是）"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="听取意见文件" prop="consultFile">
        <el-input
          v-model="queryParams.consultFile"
          placeholder="请输入听取意见文件"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="议题文件" prop="agendaFile">
        <el-input
          v-model="queryParams.agendaFile"
          placeholder="请输入议题文件"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="议题决议" prop="agendaDecision">
        <el-input
          v-model="queryParams.agendaDecision"
          placeholder="请输入议题决议"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="议题异常" prop="agendaException">
        <el-input
          v-model="queryParams.agendaException"
          placeholder="请输入议题异常"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否需要督办（0否，1是）" prop="superviseable">
        <el-input
          v-model="queryParams.superviseable"
          placeholder="请输入是否需要督办（0否，1是）"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="议题责任部门" prop="responsibleDepartment">
        <el-input
          v-model="queryParams.responsibleDepartment"
          placeholder="请输入议题责任部门"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="议题责任人" prop="responsor">
        <el-input
          v-model="queryParams.responsor"
          placeholder="请输入议题责任人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:agenda:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:agenda:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:agenda:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:agenda:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="agendaList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键id" align="center" prop="id" />
      <el-table-column label="议题名称" align="center" prop="agendaName" />
      <el-table-column label="议题编码" align="center" prop="agendaCode" />
      <el-table-column label="议题任务来源" align="center" prop="agendaResource" />
      <el-table-column label="专项名称" align="center" prop="specialItemName" />
      <el-table-column label="事项编码" align="center" prop="itemCode" />
      <el-table-column label="关联议题编码" align="center" prop="relatedAgendaCode" />
      <el-table-column label="参会人" align="center" prop="participant" />
      <el-table-column label="领导审议意见" align="center" prop="mettingComment" />
      <el-table-column label="议题是否通过（0否，1是）" align="center" prop="passable" />
      <el-table-column label="议题是否上报国资委（0否，1是）" align="center" prop="reportable" />
      <el-table-column label="是否听取意见（0否，1是）" align="center" prop="consultable" />
      <el-table-column label="听取意见文件" align="center" prop="consultFile" />
      <el-table-column label="议题文件" align="center" prop="agendaFile" />
      <el-table-column label="议题决议" align="center" prop="agendaDecision" />
      <el-table-column label="议题异常" align="center" prop="agendaException" />
      <el-table-column label="是否需要督办（0否，1是）" align="center" prop="superviseable" />
      <el-table-column label="议题责任部门" align="center" prop="responsibleDepartment" />
      <el-table-column label="议题责任人" align="center" prop="responsor" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:agenda:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:agenda:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="180px">
          <el-row>
            <el-col :span="12">
                <el-form-item label="议题名称" prop="agendaName">
                  <el-input v-model="form.agendaName" placeholder="请输入议题名称" />
                </el-form-item>
            </el-col>
                    <el-col :span="12">
                <el-form-item label="议题编码" prop="agendaCode">
                  <el-input v-model="form.agendaCode" placeholder="请输入议题编码" />
                </el-form-item>
            </el-col>
                    <el-col :span="12">
                <el-form-item label="议题任务来源" prop="agendaResource">
                  <el-input v-model="form.agendaResource" placeholder="请输入议题任务来源" />
                </el-form-item>
            </el-col>
                    <el-col :span="12">
                <el-form-item label="专项名称" prop="specialItemName">
                  <el-input v-model="form.specialItemName" placeholder="请输入专项名称" />
                </el-form-item>
            </el-col>
                    <el-col :span="12">
                <el-form-item label="事项编码" prop="itemCode">
                  <el-input v-model="form.itemCode" placeholder="请输入事项编码" />
                </el-form-item>
            </el-col>
                    <el-col :span="12">
                <el-form-item label="关联议题编码" prop="relatedAgendaCode">
                  <el-input v-model="form.relatedAgendaCode" placeholder="请输入关联议题编码" />
                </el-form-item>
            </el-col>
                    <el-col :span="12">
                <el-form-item label="参会人" prop="participant">
                  <el-input v-model="form.participant" placeholder="请输入参会人" />
                </el-form-item>
            </el-col>
                    <el-col :span="12">
                <el-form-item label="领导审议意见" prop="mettingComment">
                  <el-input v-model="form.mettingComment" placeholder="请输入领导审议意见" />
                </el-form-item>
            </el-col>
                    <el-col :span="12">
                <el-form-item label="议题是否通过（0否，1是）" prop="passable">
                  <el-input v-model="form.passable" placeholder="请输入议题是否通过（0否，1是）" />
                </el-form-item>
            </el-col>
                    <el-col :span="12">
                <el-form-item label="议题是否上报国资委（0否，1是）" prop="reportable">
                  <el-input v-model="form.reportable" placeholder="请输入议题是否上报国资委（0否，1是）" />
                </el-form-item>
            </el-col>
                    <el-col :span="12">
                <el-form-item label="是否听取意见（0否，1是）" prop="consultable">
                  <el-input v-model="form.consultable" placeholder="请输入是否听取意见（0否，1是）" />
                </el-form-item>
            </el-col>
                    <el-col :span="12">
                <el-form-item label="听取意见文件" prop="consultFile">
                  <el-input v-model="form.consultFile" placeholder="请输入听取意见文件" />
                </el-form-item>
            </el-col>
                    <el-col :span="12">
                <el-form-item label="议题文件" prop="agendaFile">
                  <el-input v-model="form.agendaFile" placeholder="请输入议题文件" />
                </el-form-item>
            </el-col>
                    <el-col :span="12">
                <el-form-item label="议题决议" prop="agendaDecision">
                  <el-input v-model="form.agendaDecision" placeholder="请输入议题决议" />
                </el-form-item>
            </el-col>
                    <el-col :span="12">
                <el-form-item label="议题异常" prop="agendaException">
                  <el-input v-model="form.agendaException" placeholder="请输入议题异常" />
                </el-form-item>
            </el-col>
                    <el-col :span="12">
                <el-form-item label="是否需要督办（0否，1是）" prop="superviseable">
                  <el-input v-model="form.superviseable" placeholder="请输入是否需要督办（0否，1是）" />
                </el-form-item>
            </el-col>
                    <el-col :span="12">
                <el-form-item label="议题责任部门" prop="responsibleDepartment">
                  <el-input v-model="form.responsibleDepartment" placeholder="请输入议题责任部门" />
                </el-form-item>
            </el-col>
                    <el-col :span="12">
                <el-form-item label="议题责任人" prop="responsor">
                  <el-input v-model="form.responsor" placeholder="请输入议题责任人" />
                </el-form-item>
            </el-col>
                </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAgenda, getAgenda, delAgenda, addAgenda, updateAgenda, exportAgenda } from "@/api/szyd/agenda";

export default {
  name: "Agenda",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      agendaList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        agendaName: undefined,
        agendaCode: undefined,
        agendaResource: undefined,
        specialItemName: undefined,
        itemCode: undefined,
        relatedAgendaCode: undefined,
        participant: undefined,
        mettingComment: undefined,
        passable: undefined,
        reportable: undefined,
        consultable: undefined,
        consultFile: undefined,
        agendaFile: undefined,
        agendaDecision: undefined,
        agendaException: undefined,
        superviseable: undefined,
        responsibleDepartment: undefined,
        responsor: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listAgenda(this.queryParams).then(response => {
        this.agendaList = response.data;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        agendaName: undefined,
        agendaCode: undefined,
        agendaResource: undefined,
        specialItemName: undefined,
        itemCode: undefined,
        relatedAgendaCode: undefined,
        participant: undefined,
        mettingComment: undefined,
        passable: undefined,
        reportable: undefined,
        consultable: undefined,
        consultFile: undefined,
        agendaFile: undefined,
        agendaDecision: undefined,
        agendaException: undefined,
        superviseable: undefined,
        responsibleDepartment: undefined,
        responsor: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAgenda(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateAgenda(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addAgenda(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delAgenda(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有【请填写功能名称】数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportAgenda(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
